package net.mysoft.budgetsoft.system.action;

import net.mysoft.budgetsoft.system.domain.TUser;
import net.mysoft.budgetsoft.system.service.UserService;
import net.mysoft.framework.base.BaseAction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * 用户action
 * @author kangrui
 *
 */
@Namespace("/user")
@Scope("prototype")
@Controller
public class UserAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3295016233166273295L;
	
	private TUser user;
	
	@Autowired
	private UserService userService;
	
	/**
	 * 用户列表
	 * @return
	 */
	@Action("datagrid")
	public String datagrid() {
		super.writeJson(userService.getUserDataGrid(super.getParaMap()));
		return null;
	}
	
	@Action("add")
	public String addUser() {
		try {
			userService.saveUser(user);
			success("保存成功！！初始密码为："+DEFAULT_PWD);
		} catch (Exception e) {
			e.printStackTrace();
			fail("保存失败！！");
		}
		return null;
	}
	
	@Action("org")
	public String org() {
		super.writeJson(userService.getOrgTree());
		return null;
	}
	
	@Action("del")
	public String del() {
		try {
			userService.delUsers(getPara("ids"));
			success("删除成功！！");
		} catch (Exception e) {
			e.printStackTrace();
			fail("删除失败！！");
		}
		return null;
	}

	public TUser getUser() {
		return user;
	}
	public void setUser(TUser user) {
		this.user = user;
	}

}
